//
//  DiaryCommentViewController.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/9/23.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "DiaryCommentViewController.h"

@interface DiaryCommentViewController ()<UITextViewDelegate>
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UILabel *placeLabel;

@end

@implementation DiaryCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发表评论";
    [self addBackItem];
    
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"发布" style:UIBarButtonItemStyleDone target:self action:@selector(handleBtn)];
    btn.tintColor = ColorFrom16(0xF5CB37);
    self.navigationItem.rightBarButtonItem = btn;
    
    _textView = [UITextView new];
    _textView.layer.borderColor = ColorFrom16(0xD0D0D0).CGColor;
    _textView.layer.borderWidth = 1;
    _textView.layer.backgroundColor = ColorWhite.CGColor;
    _textView.layer.cornerRadius = 4;
    _textView.delegate = self;
    _textView.autocorrectionType = UITextAutocorrectionTypeNo;
    [self.view addSubview:_textView];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.equalTo(@(GHEIGHT));
    }];
    
    _placeLabel = [UILabel new];
    _placeLabel.text = @"请输入评论内容";
    _placeLabel.textColor = ColorFrom16(0x949494);
    _placeLabel.font = PFRFONT(18);
    [_textView addSubview:_placeLabel];
    [_placeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_textView).offset(7);
        make.left.equalTo(_textView).offset(10);
        make.width.greaterThanOrEqualTo(@150);
        make.height.equalTo(@40);
    }];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
{
    _placeLabel.hidden = YES;
    return YES;
}
- (void)_textViewDidEndEditing:(UITextView *)textView
{
    if(textView.text.length == 0)
    {
        _placeLabel.hidden = NO;
    }
}

#pragma mark - 发布的响应方法
- (void)handleBtn
{
    if([GW_Tool isEmptyString:_textView.text])
    {
        MESSAGE_TOAST(@"请输入反馈内容");
        return;
    }
    NSDictionary *param = @{@"content":_textView.text,
                            @"did"    :self.goodid};
    @weakobj(self);
    [NetWork sendPostRequestURL:[NSString stringWithFormat:@"%@/diary/CommitComment", GW_Domain] parameters:param completionBlockWithSuccess:^(NSDictionary *resultDict) {
        @strongobj(self);
        MESSAGE_TOAST(resultDict[@"message"]);
        self.refresgBlock();
        [self.navigationController popViewControllerAnimated:YES];
    } andFailure:^(NSError *error, NSString *errorMsg) {
        NSLog(@"%@", error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
